home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / src / portable / insstr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  7.1 KB  |  228 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. #define    CURSES_LIBRARY    1
  20. #include <curses.h>
  21.  
  22. /* undefine any macros for functions defined in this module */
  23. #undef    insstr
  24. #undef    insnstr
  25. #undef    winsstr
  26. #undef    winsnstr
  27. #undef    mvinsstr
  28. #undef    mvinsnstr
  29. #undef    mvwinsstr
  30. #undef    mvwinsnstr
  31.  
  32. /* undefine any macros for functions called by this module if in debug mode */
  33. #ifdef PDCDEBUG
  34. #  undef    move
  35. #  undef    wmove
  36. #  undef    addch
  37. #  undef    waddch
  38. #endif
  39.  
  40. #ifdef PDCDEBUG
  41. char *rcsid_insstr  = "$Id$";
  42. #endif
  43.  
  44. /*man-start*********************************************************************
  45.  
  46.   Name:                                                        insstr
  47.  
  48.   Synopsis:
  49.       int insstr(char *str);
  50.       int insnstr(char *str, int n);
  51.       int winsstr(WINDOW *win, char *str);
  52.       int winsnstr(WINDOW *win, char *str, int n);
  53.       int mvinsstr(int y, int x, char *str);
  54.       int mvinsnstr(int y, int x, char *str, int n);
  55.       int mvwinsstr(WINDOW *, int y, int x, char *str);
  56.       int mvwinsnstr(WINDOW *, int y, int x, char *str, int n);
  57.  
  58.   System V Curses Description:
  59.       With these routines, a character string (as many characters as 
  60.       will fit on the line) is inserted before the character under 
  61.       the cursor.  All characters to the right of the cursor are moved 
  62.       to the right, with the possibility of the rightmost characters 
  63.       on the line being lost.  The cursor position does not change 
  64.       (after moving to y,x if specified).  The four routines with n as 
  65.       the last argument insert at most n characters.  If n<=0, then 
  66.       the entire string is inserted.
  67.  
  68.      NOTE:    insstr(), mvinsstr(), and mvwinsstr() are implemented as macros.
  69.          insnstr(), mvinsnstr(), and mvwinsnstr() are implemented as macros.
  70.  
  71.   PDCurses Description:
  72.      The *raw*() routines output 8 bit values.  These contrast to their
  73.      normal counterparts which output 7 bit values and convert control
  74.      character to the ^X notation.
  75.  
  76.      str is a standard 8 bit character string WITHOUT embedded attributes.
  77.  
  78.   X/Open Return Value:
  79.      All functions return OK on success and ERR on error.
  80.  
  81.   X/Open Errors:
  82.      No errors are defined for this function.
  83.  
  84.   Portability                             X/Open    BSD    SYS V
  85.                                           Dec '88
  86.       insstr                                -        -      4.0
  87.       winsstr                               -        -      4.0
  88.       mvinsstr                              -        -      4.0
  89.       mvwinsstr                             -        -      4.0
  90.       insnstr                               -        -      4.0
  91.       winsnstr                              -        -      4.0
  92.       mvinsnstr                             -        -      4.0
  93.       mvwinsnstr                            -        -      4.0
  94.  
  95. **man-end**********************************************************************/
  96.  
  97. /***********************************************************************/
  98. int    insstr(char *str)
  99. /***********************************************************************/
  100. {
  101. #ifdef PDCDEBUG
  102.     if (trace_on) PDC_debug("insstr() - called: string=\"%s\"\n",str);
  103. #endif
  104.  
  105.     if (stdscr == (WINDOW *)NULL)
  106.         return( ERR );
  107.  
  108.     return(winsnstr(stdscr,str,(-1)));
  109. }
  110. /***********************************************************************/
  111. int    insnstr(char *str, int n)
  112. /***********************************************************************/
  113. {
  114. #ifdef PDCDEBUG
  115.     if (trace_on) PDC_debug("insnstr() - called: string=\"%s\" n %d \n",str,n);
  116. #endif
  117.  
  118.     if (stdscr == (WINDOW *)NULL)
  119.         return( ERR );
  120.  
  121.     return(winsnstr(stdscr,str,n));
  122. }
  123. /***********************************************************************/
  124. int    winsstr(WINDOW *win, char *str)
  125. /***********************************************************************/
  126. {
  127. #ifdef PDCDEBUG
  128.     if (trace_on) PDC_debug("winsstr() - called: string=\"%s\"\n",str);
  129. #endif
  130.  
  131.     if (win == (WINDOW *)NULL)
  132.         return( ERR );
  133.  
  134.     return(winsnstr(win,str,(-1)));
  135. }
  136. /***********************************************************************/
  137. int    winsnstr(WINDOW *win, char *str, int n)
  138. /***********************************************************************/
  139. {
  140.     int ic = strlen(str);
  141.  
  142. #ifdef PDCDEBUG
  143.     if (trace_on) PDC_debug("winsnstr() - called: string=\"%s\" n %d \n",str,n);
  144. #endif
  145.  
  146.     if (win == (WINDOW *)NULL)
  147.         return( ERR );
  148.  
  149.     if( n > 0 )
  150.         ic = ((ic<n)?ic:n) - 1;
  151.     else
  152.         ic = ic - 1;
  153.  
  154.     for ( ; ic >= 0; ic-- )
  155.     {
  156.         if (winsch(win, *(str+ic) ) == ERR)
  157.         {
  158.             return( ERR );
  159.         }
  160.     }
  161.     return( OK );
  162. }
  163. /***********************************************************************/
  164. int    mvinsstr(int y, int x, char *str)
  165. /***********************************************************************/
  166. {
  167. #ifdef PDCDEBUG
  168.     if (trace_on) PDC_debug("mvinsstr() - called: y %d x %d string=\"%s\"\n",y,x,str);
  169. #endif
  170.  
  171.     if (stdscr == (WINDOW *)NULL)
  172.         return( ERR );
  173.  
  174.     if (move(y,x) == ERR)
  175.         return( ERR );
  176.  
  177.     return(winsnstr(stdscr,str,(-1)));
  178. }
  179. /***********************************************************************/
  180. int    mvinsnstr(int y, int x, char *str, int n)
  181. /***********************************************************************/
  182. {
  183. #ifdef PDCDEBUG
  184.     if (trace_on) PDC_debug("mvinsnstr() - called: y %d x %d string=\"%s\" n %d \n",y,x,str,n);
  185. #endif
  186.  
  187.     if (stdscr == (WINDOW *)NULL)
  188.         return( ERR );
  189.  
  190.     if (move(y,x) == ERR)
  191.         return( ERR );
  192.  
  193.     return(winsnstr(stdscr,str,n));
  194. }
  195. /***********************************************************************/
  196. int    mvwinsstr(WINDOW *win, int y, int x, char *str)
  197. /***********************************************************************/
  198. {
  199. #ifdef PDCDEBUG
  200.     if (trace_on) PDC_debug("winsstr() - called: string=\"%s\"\n",str);
  201. #endif
  202.  
  203.     if (win == (WINDOW *)NULL)
  204.         return( ERR );
  205.  
  206.     if (wmove(win,y,x) == ERR)
  207.         return( ERR );
  208.  
  209.     return(winsnstr(win,str,(-1)));
  210. }
  211. /***********************************************************************/
  212. int    mvwinsnstr(WINDOW *win,int y, int x, char *str, int n)
  213. /***********************************************************************/
  214. {
  215. #ifdef PDCDEBUG
  216.     if (trace_on) PDC_debug("mvwinsnstr() - called: y %d x %d string=\"%s\" n %d \n",y,x,str,n);
  217. #endif
  218.  
  219.     if (win == (WINDOW *)NULL)
  220.         return( ERR );
  221.  
  222.     if (wmove(win,y,x) == ERR)
  223.         return( ERR );
  224.  
  225.     return(winsnstr(win,str,n));
  226. }
  227.